import datetime
from django.core.management.base import BaseCommand
from service.models import Month


class Command(BaseCommand):
    help = 'Create Month instances for the current year'

    def handle(self, *args, **kwargs):
        current_year = datetime.datetime.now().year

        # Check if Month instances already exist for the current year
        existing_months = Month.objects.filter(year=current_year).count()
        if existing_months == 0:
            for month in range(1, 13):
                Month.objects.create(year=current_year, month=month)
            self.stdout.write(self.style.SUCCESS('Successfully created Month instances for the current year'))
        else:
            self.stdout.write(self.style.WARNING('Month instances for the current year already exist'))
